package com.lian.community.async;

import com.alibaba.fastjson.JSONObject;
import com.lian.community.dao.redis.JedisDAO;
import com.lian.community.util.RedisKeyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 事件生产者，把事件推送进队列
 */
@Component
public class EventProducer {

    @Autowired
    JedisDAO jedisDAO;

    public boolean add(EventModel eventModel){

        String key = null;
        try {
            System.out.println(eventModel);
            key = RedisKeyUtil.getEventKey();
            String eventJson = JSONObject.toJSONString(eventModel);
            jedisDAO.lpush(key, eventJson);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}
